package ru.tennisworld.match.controllers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import ru.tennisworld.match.controller.MatchController;
import ru.tennisworld.match.dto.match.CreateMatchRequestDto;
import ru.tennisworld.match.dto.match.MatchFullResponseDto;
import ru.tennisworld.match.dto.match.UpdateMatchRequestDto;
import ru.tennisworld.match.services.match.MatchControllerService;

@RestController
public class MatchControllerImpl implements MatchController {

    @Autowired
    private MatchControllerService matchControllerService;

    private static final Logger LOG = LoggerFactory.getLogger(MatchControllerImpl.class);

    @Override
    public ResponseEntity<MatchFullResponseDto> getMatchFullInfo(String matchId) {
        LOG.info("operation=MatchControllerImpl.getMatchFullInfo, action=start, matchId={}", matchId);
        MatchFullResponseDto result = matchControllerService.getFullInfo(matchId);
        LOG.info("operation=MatchControllerImpl.getMatchFullInfo, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @Override
    public ResponseEntity<MatchFullResponseDto> createSingleMatch(CreateMatchRequestDto request) {
        LOG.info("operation=MatchControllerImpl.createSingleMatch, action=start, request={}", request);
        MatchFullResponseDto result = matchControllerService.createSingleMatch(request);
        LOG.info("operation=MatchControllerImpl.createSingleMatch, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @Override
    public ResponseEntity<MatchFullResponseDto> updateSingleMatch(String matchId, UpdateMatchRequestDto request) {
        LOG.info("operation=MatchControllerImpl.updateSingleMatch, action=start, request={}", request);
        MatchFullResponseDto result = matchControllerService.updateSingleMatch(matchId, request);
        LOG.info("operation=MatchControllerImpl.updateSingleMatch, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}
